package com.cskaoyan.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @program: project-market
 * @description:正则表达校验工具类
 * @author: zhijie
 * @create: 2021-11-30 11:37
 **/

public class RegularUtil {
    /**
     * 校验字符串是否是合法的手机号
     *
     * @param mobile
     * @return
     */
    public static boolean isMobile(String mobile) {
        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(16[5,6])|(17[0-8])|(18[0-9])|(19[1、5、8、9]))\\d{8}$";
        Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(mobile);
        return m.matches();
    }

    /**
     * 正整数校验
     * @param number
     * @return
     */
    public static boolean isNumber(String number) {
        String regex = "^\\d+$";
        Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(number);
        return m.matches();
    }

}
